<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="disableSubmit">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="8">
              <a-form-model-item label="标段名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sectionName">
                <a-input v-model="model.sectionName" placeholder="请输入标段名称"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="标段编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sectionCode">
                <a-input v-model="model.sectionCode" placeholder="请输入标段编号"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="价款形式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jkxs">
                <j-dict-select-tag
                  type="list"
                  v-model="model.jkxs"
                  dictCode="sys_price_type"
                  placeholder="请选择价款形式"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="招标类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zblb">
                <j-dict-select-tag
                  type="list"
                  v-model="model.zblb"
                  dictCode="sys_zb_type"
                  placeholder="请选择招标类别"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="合同估算价(万元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="htgsj">
                <a-input-number v-model="model.htgsj" placeholder="请输入合同估算价(万元)"></a-input-number>
              </a-form-model-item>
            </a-col>
            <a-col :span="8">
              <a-form-model-item label="标段分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sectionType">
                <!--
                <j-dict-select-tag
                  type="list"
                  v-model="model.sectionType"
                  dictCode="sys_project_section_category"
                  placeholder="请选择标段分类"
                />
                -->
                <j-category-select ref="sectionTypeRef" v-model="model.sectionType" pcode="标段分类"/>
              </a-form-model-item>
            </a-col>
            <!-- <a-col :span="8">
              <a-form-model-item label="显示序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sortNum">
                <a-input v-model="model.sortNum" placeholder="请输入显示序号"></a-input>
              </a-form-model-item>
            </a-col> -->
            <a-col :span="8">
              <a-form-model-item label="计划开工日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jhkgrq">
                <j-date placeholder="请选择计划开工日期" v-model="model.jhkgrq" style="width: 100%" />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item 
              label="工程规模"  
              :labelCol="{ lg: { span: 3 }, sm: { span: 3} }"
                :wrapperCol="{ lg: { span: 21 }, sm: { span: 20 } }" 
                prop="gcgm">
                <!--
                <a-input v-model="model.gcgm" placeholder="请输入工程规模"></a-input>
                -->
                <a-textarea v-model="model.gcgm" rows="4" placeholder="请输入要求投标人资质等级" />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                label="要求投标人资质等级"
                :labelCol="{ lg: { span: 3 }, sm: { span: 4 } }"
                :wrapperCol="{ lg: { span: 21 }, sm: { span: 20 } }"
                prop="yqtbrzzdj" 
              >
              <a-textarea v-model="model.yqtbrzzdj" rows="4" placeholder="请输入要求投标人资质等级" />
              <!--
                <a-input v-model="model.yqtbrzzdj" placeholder="请输入要求投标人资质等级"></a-input>
                -->
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item
                label="工程概况"
                :labelCol="{ lg: { span: 3}, sm: { span: 4 } }"
                :wrapperCol="{ lg: { span: 21 }, sm: { span: 20 } }"
                prop="gcgk"
              >
                <a-textarea v-model="model.gcgk" rows="4" placeholder="请输入工程概况" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-spin> 
  </j-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import { randomUUID } from '@/utils/util'
export default {
  name: 'GcProjectEntrySectionModal',
  components: {},
  data() {
    return {
      title: '',
      width: 1024,
      visible: false,
      disableSubmit: false,

      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 9 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 15 },
      },
      confirmLoading: false,
      validatorRules: {
        entryId: [{ required: true, message: '请输入进场表主键!' }],
        sectionName: [{ required: true, message: '请输入标段名称!' }],
        sectionCode: [{ required: true, message: '请输入标段编号!' }],
        jkxs:[{ required: true, message: '请选择价款形式!' }],
        zblb:[{ required: true, message: '请选择招标类别!' }],
        htgsj:[{ required: true, message: '请输入合同估算价!' }],
        sectionType:[{ required: true, message: '请选择标段分类!' }],
      },
      url: {
        add: '/gcProject/gcProjectEntrySection/add',
        edit: '/gcProject/gcProjectEntrySection/edit',
        queryById: '/gcProject/gcProjectEntrySection/queryById',
      },
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.visible = true
      var obj = this.modelDefault
      obj.id = randomUUID()
      this.edit(obj)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.model.bdType = that.$refs.sectionTypeRef.treeValue[0].label
          that.$emit('ok', that.model)
          that.visible = false
        }
      })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>
<style scoped>
/* 自定义样式实现自动换行 */
.ant-form-item-label label{
  white-space: normal; /* 或者使用 word-wrap: break-word; */
  word-break: break-all; /* 可选，根据需求决定是否使用 */
}
</style>